﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Quick Start - Layui</title>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
    <style>
        /* 为layui-form-label设置样式 */
        .layui-form-label {
            width: 135px; /* 调整label的宽度 */
            font-size: 14px; /* 调整label的字体大小 */
        }

        /* 可选：为layui-input-block设置样式，调整其宽度或内边距 */
        .layui-input-block {
            margin-left: 170px; /* 根据label的宽度设置左外边距，使得input与label对齐 */
        }
    </style>
</head>
<body>
    @* 设置背景颜色为灰色 *@
    <div class="layui-bg-gray" style="padding:16px 100px 16px 100px;">
        @* layui-panel 创建一个面板样式的容器 *@
        <div class="layui-panel" style="width:100%;">
            @* layui-card 创建一个卡片样式的容器*@
            @* 你可以根据需要调整这里的宽度和高度 *@
            <div class="layui-card">
                @* 标题 *@
                <div class="layui-card-header">
                    <h3 style="color: #34c38f;float:left">
                        <i class="layui-icon layui-icon-left" style="color: #dcccc0"></i><a style="color: #e2e2e2;cursor:pointer" href="/PurchaseOutsource/PurchaseOutsourceInfo">返回&nbsp;&nbsp;</a><span style="color: #000">|</span>&nbsp;&nbsp;采购/委外订单头信息&nbsp;<span style="color: #000"><i class="layui-icon layui-icon-note"></i></span>
                    </h3>
                    <div style="float:right">
                        <button type="button" class="layui-btn layui-border layui-icon layui-icon-print" id="Print" onclick="PrintPurchase()">打印</button>
                    </div>
                    @* 墨绿分割线 *@
                    <hr class="layui-border-green">
                </div>
                @* 主体 *@
                <div class="layui-card-body">
                    <!--选项卡-->
                    <div class="layui-tab" lay-filter="test-hash">
                        <!--标签-->
                        <ul class="layui-tab-title">
                            <li class="layui-this" lay-id="1">标准信息</li>
                        </ul>
                        <!--内容-->
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <form class="layui-form layui-row layui-col-space16">
                                    <!--订单编码-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">订单编码</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="purchaseNumber" placeholder="请输入" class="layui-input" disabled>
                                            </div>
                                        </div>
                                    </div>
                                    <!--订单名称-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">订单名称</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="purchaseName" placeholder="请输入" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <!--订单类型-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">订单类型</label>
                                            <div class="layui-input-block">
                                                <select name="purchaseTypeId"></select>
                                            </div>
                                        </div>
                                    </div>
                                    <!--所属项目-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">所属项目</label>
                                            <div class="layui-input-block">
                                                <select name="affiliatedProjectId"></select>
                                            </div>
                                        </div>
                                    </div>
                                    <!--协议编码-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">协议编码</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="protocolCoding" placeholder="请输入" class="layui-input" disabled>
                                            </div>
                                        </div>
                                    </div>
                                    <!--协议名称-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">协议名称</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="protocolName" placeholder="请输入" class="layui-input" disabled>
                                            </div>
                                        </div>
                                    </div>
                                    <!--订单备注-->
                                    <div class="layui-col-md12">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">订单备注</label>
                                            <div class="layui-input-block">
                                                <textarea name="purchaseNote" placeholder="请输入" class="layui-textarea"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <!--供应商-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">供应商</label>
                                            <div class="layui-input-block">
                                                <select name="supplierId"></select>
                                            </div>
                                        </div>
                                    </div>
                                    <!--订单金额(不含税)-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">订单金额(不含税)</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="orderAmount" class="layui-input" disabled>
                                                <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                                                    <div style="padding-top:50%">(元)</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--币种-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">币种</label>
                                            <div class="layui-input-block">
                                                <select name="currencyId"></select>
                                            </div>
                                        </div>
                                    </div>
                                    <!--预付款金额-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">预付款金额</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="paymentAmount" placeholder="请输入" class="layui-input">
                                                <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                                                    <div style="padding-top:50%;">(元)</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--订单开始时间-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">订单开始时间</label>
                                            <div class="layui-input-block layui-input-wrap">
                                                <div class="layui-input-prefix">
                                                    <i class="layui-icon layui-icon-date"></i>
                                                </div>
                                                <input type="text" name="startTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <!--订单结束时间-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">订单结束时间</label>
                                            <div class="layui-input-block layui-input-wrap">
                                                <div class="layui-input-prefix">
                                                    <i class="layui-icon layui-icon-date"></i>
                                                </div>
                                                <input type="text" name="endTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <!--签订时间-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">签订时间</label>
                                            <div class="layui-input-block layui-input-wrap">
                                                <div class="layui-input-prefix">
                                                    <i class="layui-icon layui-icon-date"></i>
                                                </div>
                                                <input type="text" name="theDateOfSigning" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <!--状态-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">状态</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="purchaseStatus" class="layui-input" disabled>
                                            </div>
                                        </div>
                                    </div>
                                    <!--计税类型-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">计税类型</label>
                                            <div class="layui-input-block">
                                                <select name="taxType">
                                                    <option value="">请选择</option>
                                                    <option value="增值税">增值税</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <!--税率-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">税率</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="taxRate" placeholder="请输入" class="layui-input">
                                                <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                                                    <div style="padding-top:50%">%</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--开票金额(含税)-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">开票金额(含税)</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="" class="layui-input" disabled>
                                                <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                                                    <div style="padding-top:50%">(元)</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--已付款金额(含税)-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">已付款金额(含税)</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="" class="layui-input" disabled>
                                                <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                                                    <div style="padding-top:50%">(元)</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--制单人-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">制单人</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="preparedBy" placeholder="请输入" class="layui-input" disabled>
                                            </div>
                                        </div>
                                    </div>
                                    <!--制单部门-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="margin-bottom: 0;">
                                            <label class="layui-form-label">制单部门</label>
                                            <div class="layui-input-block">
                                                <select name="departmentId"></select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-col-md6"></div>
                                    <!--按钮-->
                                    <div class="layui-col-md6">
                                        <div class="layui-form-item" style="float:right;">
                                            <div class="layui-input-block">
                                                <button type="submit" class="layui-btn layui-icon layui-icon-add-1" lay-submit lay-filter="demo-val">保存</button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 采购/委外订单行信息 -->
        <div class="layui-panel" style="width:100%;">
            <div class="layui-card">
                <!-- 标题 -->
                <div class="layui-card-header">
                    <h3 style="color: #34c38f">
                        <span style="color:#1e9fff;">采购/委外订单行信息</span>
                    </h3>
                    <!-- 蓝色分割线 -->
                    <hr class="layui-border-blue">
                </div>
                <!--主体-->
                <div class="layui-card-body">
                    <div class="layui-tab" lay-filter="test-hash">
                        <ul class="layui-tab-title">
                            <li class="layui-this" lay-id="1">订单行</li>
                            <li lay-id="2">付款计划行</li>
                        </ul>
                        <div class="layui-tab-content">
                            <!--订单行-->
                            <div class="layui-tab-item layui-show">
                                @* 弹出框 *@
                                <button type="button" style="float:right;margin-bottom:10px" class="layui-btn layui-bg-blue layui-btn-sm layui-icon layui-icon-addition" id="orderBank">新增订单行</button>
                                <table class="layui-table">
                                    <thead style="background-color:#f7f7f7">
                                        <tr>
                                            <th>行号</th>
                                            <th>物料编码</th>
                                            <th>物料名称</th>
                                            <th>单价(不含税)</th>
                                            <th>数量</th>
                                            <th>单位</th>
                                            <th>金额(不含税)</th>
                                            <th>摘要</th>
                                            <th>创建时间</th>
                                            <th>创建人</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="order"></tbody>
                                </table>
                                <div id="demo-order-all"></div>
                            </div>
                            <!--付款计划行-->
                            <div class="layui-tab-item">
                                @* 弹出框 *@
                                <button type="button" style="float:right;margin-bottom:10px" class="layui-btn layui-bg-blue layui-btn-sm layui-icon layui-icon-addition" id="paymentButton">新增付款计划</button>
                                <table class="layui-table">
                                    <thead style="background-color:#f7f7f7">
                                        <tr>
                                            <th>行号</th>
                                            <th>付款计划时间</th>
                                            <th>付款比例(%)</th>
                                            <th>付款金额(不含税)</th>
                                            <th>预付款</th>
                                            <th>开票金额(含税)</th>
                                            <th>已付款金额(含税)</th>
                                            <th>备注</th>
                                            <th>创建时间</th>
                                            <th>创建人</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="payment"></tbody>
                                </table>
                                <div id="demo-payment-all"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        //主键ID
        var purchaseId = 0;
        // 使用layui的layer模块
        layui.use(['form', 'layer'], function () {
            var $ = layui.$;
            var form = layui.form;
            var table = layui.table;
            var laypage = layui.laypage;
            var laydate = layui.laydate;

            //获取分页数据
            var pageIndex = 1;
            var pageSize = 3;

            //获取采购/委外编号
            var PurchaseNumber = location.search.split("=")[1];

            //获取订单类型
            $.ajax({
                url: '@ViewBag.RedDragonWrite' + "/api/Purchase/SearchPurchaseType",
                type: 'GET',
                dataType: 'json',
                success: res => {
                    console.log(res)
                    var options = '<option value="0">请选择</option>';
                    $.each(res.data, function (index, item) {
                        options += '<option value="' + item.purchaseTypeId + '">' + item.purchaseTypeName + '</option>';
                    });
                    $('[name="purchaseTypeId"]').html(options);
                    form.render('select'); // 更新下拉框渲染
                }
            });

            //获取所属项目
            $.ajax({
                url: '@ViewBag.RedDragonWrite' + "/api/Purchase/SearchAffiliatedProject",
                type: 'GET',
                dataType: 'json',
                success: res => {
                    console.log(res)
                    var options = '<option value="0">请选择</option>';
                    $.each(res.data, function (index, item) {
                        options += '<option value="' + item.affiliatedProjectId + '">' + item.affiliatedProjectName + '</option>';
                    });
                    $('[name="affiliatedProjectId"]').html(options);
                    form.render('select'); // 更新下拉框渲染
                }
            });

            //获取供应商
            $.ajax({
                url: '@ViewBag.RedDragonWrite' + "/api/Purchase/SearchAllSupplier",
                type: 'GET',
                dataType: 'json',
                success: res => {
                    console.log(res)
                    var options = '<option value="0">请选择</option>';
                    $.each(res.data, function (index, item) {
                        options += '<option value="' + item.supplierId + '">' + item.supplierName + '（' + item.supplierCoding + '）电话:' + item.supplierPhone + '</option>';
                    });
                    $('[name="supplierId"]').html(options);
                    form.render('select'); // 更新下拉框渲染
                }
            });

            //获取币种
            $.ajax({
                url: '@ViewBag.RedDragonWrite' + "/api/Purchase/SearchCurrency",
                type: 'GET',
                dataType: 'json',
                success: res => {
                    console.log(res)
                    var options = '<option value="0">请选择</option>';
                    $.each(res.data, function (index, item) {
                        options += '<option value="' + item.currencyId + '">' + item.currencyName + '</option>';
                    });
                    $('[name="currencyId"]').html(options);
                    form.render('select'); // 更新下拉框渲染
                }
            });

            //获取部门
            $.ajax({
                url: '@ViewBag.RedDragonWrite' + "/api/Enterprises/SearchAllDepartment",
                type: 'GET',
                dataType: 'json',
                success: res => {
                    console.log(res)
                    var options = '<option value="0">请选择</option>';
                    $.each(res.data, function (index, item) {
                        options += '<option value="' + item.departmentId + '">' + item.departmentName + '</option>';
                    });
                    $('[name="departmentId"]').html(options);
                    form.render('select'); // 更新下拉框渲染
                }
            });

            // 日期
            laydate.render({
                elem: '#date'
            });


            //创建人
            var createdOwner = '';
            //创建日期
            var createTime = '';
            //获取采购/委外订单重新反填
            $.ajax({
                url: '@ViewBag.RedDragonWrite' + "/api/Purchase/DetailPurchase",
                type: 'post',
                data: JSON.stringify({ PurchaseNumber: PurchaseNumber }),
                dataType: 'json',
                contentType: "application/json",
                success: res => {
                    console.log("反填", res)
                    //日期转换
                    res.data.startTime = moment(res.data.startTime).format("YYYY-MM-DD")
                    res.data.endTime = moment(res.data.endTime).format("YYYY-MM-DD")
                    res.data.theDateOfSigning = moment(res.data.theDateOfSigning).format("YYYY-MM-DD")
                    //获取主键
                    purchaseId = res.data.purchaseId;
                    $('[name="purchaseNumber"]').val(res.data.purchaseNumber);
                    $('[name="purchaseName"]').val(res.data.purchaseName);
                    $('[name="purchaseTypeId"]').val(res.data.purchaseTypeId);
                    $('[name="affiliatedProjectId"]').val(res.data.affiliatedProjectId);
                    $('[name="protocolCoding"]').val(res.data.protocolCoding);
                    $('[name="protocolName"]').val(res.data.protocolName);
                    $('[name="purchaseNote"]').val(res.data.purchaseNote);
                    $('[name="supplierId"]').val(res.data.supplierId);
                    $('[name="orderAmount"]').val(res.data.orderAmount);
                    $('[name="currencyId"]').val(res.data.currencyId);
                    $('[name="paymentAmount"]').val(res.data.paymentAmount);
                    $('[name="startTime"]').val(res.data.startTime);
                    $('[name="endTime"]').val(res.data.endTime);
                    $('[name="theDateOfSigning"]').val(res.data.theDateOfSigning);
                    $('[name="purchaseStatus"]').val(res.data.purchaseStatus == 1 ? "新建" : "确认");
                    $('[name="taxType"]').val(res.data.taxType);
                    $('[name="taxRate"]').val(res.data.taxRate);
                    $('[name="preparedBy"]').val(res.data.preparedBy);
                    $('[name="departmentId"]').val(res.data.departmentId);
                    createdOwner = res.data.createdOwner;
                    createTime = res.data.createdTime;
                    //获取订单行
                    SearchOrderBank(pageIndex, pageSize);
                    //获取付款计划行
                    SearchPayment(pageIndex, pageSize)
                    form.render(); // 更新渲染
                }
            });

            // 提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值
                field.purchaseId = purchaseId;
                field.purchaseStatus = $('[name="purchaseStatus"]').val() == "新建" ? 1 : 2;
                field.createdOwner = createdOwner;
                field.createdTime = createTime;
                field.updateOwner = localStorage.getItem('userName');
                console.log(field) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "PUT",
                    url: '@ViewBag.RedDragonWrite' + "/api/Purchase/UpdatePurchase",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        // 处理响应，例如提示成功信息
                        layui.layer.msg(res.msg, { icon: 6, time: 1000 });
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('修改失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });

            // 订单行弹窗
            $('#orderBank').on('click', function () {
                layer.open({
                    type: 2,
                    title: '采购订单行编辑',
                    offset: 'auto',
                    area: ['500px', '500px'],
                    content: '/PurchaseOutsource/CreateOrderBank?Number=' + $('[name="purchaseNumber"]').val(),
                    end: function () { // 弹出层关闭后执行的回调
                        SearchOrderBank(pageIndex, pageSize);
                    }
                });
            });

            // 付款计划弹窗
            $('#paymentButton').on('click', function () {
                layer.open({
                    type: 2,
                    title: '付款计划行编辑',
                    offset: 'auto',
                    area: ['550px', '500px'],
                    content: '/PurchaseOutsource/CreatePayment?Number=' + $('[name="purchaseNumber"]').val(),
                    end: function () { // 弹出层关闭后执行的回调
                        SearchPayment(pageIndex, pageSize)
                    }
                });
            });

            //订单金额
            var OrderPrice = 0;

            //-----------------获取订单行列表--------------------//
            function SearchOrderBank(index, size) {
                //获取数据
                var data = {
                    purchaseNumber: $('[name="purchaseNumber"]').val(),
                    pageIndex: index,
                    pageSize: size,
                }
                console.log(data);
                var totalCount = 0;//总条数
                var totalPage = 0;//总页数
                //获取
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/Purchase/SearchOrderBank",
                    type: 'post',
                    data: JSON.stringify(data),
                    dataType: 'json',
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $("#order").empty();
                        if (res.data != null) {
                            totalCount = res.data.totalCount;
                            totalPage = res.data.pageCount;
                            $.each(res.data.list, function (index, item) {
                                item.createdTime = moment(item.createdTime).format("YYYY-MM-DD HH:mm:ss")
                                $("#order").append(`<tr>` +
                                    `<td>${item.orderBankId}</td>` +
                                    `<td>${item.materialCode}</td>` +
                                    `<td>${item.materialName}</td>` +
                                    `<td>${item.unitprice}</td>` +
                                    `<td>${item.quantity}</td>` +
                                    `<td>${item.unitName}</td>` +
                                    `<td>${item.bankAmount}</td>` +
                                    `<td>${item.abstract}</td>` +
                                    `<td>${item.createdTime}</td>` +
                                    `<td>${item.createdOwner}</td>` +
                                    `<td>操作</td>` +
                                    `</tr>`)
                                //将订单金额循环添加
                                OrderPrice += item.bankAmount
                            });
                            $('[name="orderAmount"]').val(OrderPrice);
                        }
                        laypage.render({
                            elem: 'demo-order-all',
                            curr: data.pageIndex,//当前页
                            limit: data.pageSize,//每页显示条数
                            limits: [3, 6, 9, 12],//每页条数的选择项
                            count: totalCount, // 数据总数，从后端得到
                            first: "首页",
                            prev: "上一页",
                            next: "下一页",
                            last: "尾页",
                            layout: ['count', 'first', 'prev', 'page', 'next', 'last', 'limit', 'skip'], // 自定义布局
                            jump: function (obj, first) {
                                console.log("分页", obj);
                                // 首次不执行
                                if (!first) {
                                    pageIndex = obj.curr;
                                    pageSize = obj.limit;
                                    SearchOrderBank(pageIndex, pageSize);
                                }
                            }
                        });
                    }
                });
            }

            //-----------------获取付款计划行列表--------------------//
            function SearchPayment(index, size) {
                //获取数据
                var data = {
                    purchaseNumber: $('[name="purchaseNumber"]').val(),
                    pageIndex: index,
                    pageSize: size,
                }
                console.log(data);
                var totalCount = 0;//总条数
                var totalPage = 0;//总页数
                //获取
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/Purchase/SearchPayment",
                    type: 'post',
                    data: JSON.stringify(data),
                    dataType: 'json',
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $("#payment").empty();
                        if (res.data != null) {
                            totalCount = res.data.totalCount;
                            totalPage = res.data.pageCount;
                            $.each(res.data.list, function (index, item) {
                                item.scheduleTime = moment(item.scheduleTime).format("YYYY-MM-DD HH:mm:ss")
                                item.createdTime = moment(item.createdTime).format("YYYY-MM-DD HH:mm:ss")
                                $("#payment").append(`<tr>` +
                                    `<td>${item.paymentId}</td>` +
                                    `<td>${item.scheduleTime}</td>` +
                                    `<td>${item.paymentRatio}</td>` +
                                    `<td>${item.paymentAmount}</td>` +
                                    `<td>${item.advance}</td>` +
                                    `<td>${item.invoiceAmount}</td>` +
                                    `<td>${item.amountPaid}</td>` +
                                    `<td>${item.remark}</td>` +
                                    `<td>${item.createdTime}</td>` +
                                    `<td>${item.createdOwner}</td>` +
                                    `<td>操作</td>` +
                                    `</tr>`)
                            });
                        }
                        laypage.render({
                            elem: 'demo-payment-all',
                            curr: data.pageIndex,//当前页
                            limit: data.pageSize,//每页显示条数
                            limits: [3, 6, 9, 12],//每页条数的选择项
                            count: totalCount, // 数据总数，从后端得到
                            first: "首页",
                            prev: "上一页",
                            next: "下一页",
                            last: "尾页",
                            layout: ['count', 'first', 'prev', 'page', 'next', 'last', 'limit', 'skip'], // 自定义布局
                            jump: function (obj, first) {
                                console.log("分页", obj);
                                // 首次不执行
                                if (!first) {
                                    pageIndex = obj.curr;
                                    pageSize = obj.limit;
                                    SearchPayment(pageIndex, pageSize);
                                }
                            }
                        });
                    }
                });
            }
        });

        //打印
        function PrintPurchase() {
            location.href = '@ViewBag.RedDragonWrite' + "/api/Stamp/GetPDF?Id=" + purchaseId;
        }
    </script>
</body>
</html>
